package com.lanchetech.admin.controller;

import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.admin.service.VideoService;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.VideoVO;
import com.lanchetech.entity.Video;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(value = "视频接口", tags = "视频接口")
@RequestMapping("/api/video")
@RestController
public class VideoController {

    @Autowired
    VideoService videoService;

    @ApiOperation("获取视频详细信息")
    @GetMapping("/getVideoDetail")
    public ResultData<VideoVO> getVideoDetail(@RequestParam("id") Long id) {
        return videoService.getVideoDetail(id);
    }

    @OperatorLog("创建和编辑视频")
    @ApiOperation("创建和编辑视频")
    @PreAuthorize("hasAuthority('web.video-index.edit.auth')")
    @PostMapping("/editVideo")
    public BaseResp editVideo(@RequestBody Video video) {
        return videoService.editVideo(video);
    }

    @ApiOperation("获取所有视频列表")
    @PreAuthorize("hasAuthority('web.video-index')")
    @PostMapping("/getVideoPage")
    public ResultData<BasePageResp<VideoVO>> getVideoPage(@RequestBody PageReq req) {
        return videoService.getVideoPage(req);
    }

    @OperatorLog("删除视频")
    @ApiOperation("删除视频")
    @PreAuthorize("hasAuthority('web.video-index.edit.auth')")
    @GetMapping("/deleteVideo")
    public BaseResp deleteVideo(@RequestParam("id") Long id) {
        return videoService.deleteVideo(id);
    }

    @OperatorLog("审核视频")
    @ApiOperation("审核视频")
    @PreAuthorize("hasAuthority('web.video-index.edit.auth')")
    @PostMapping("/auditVideo")
    public BaseResp auditVideo(@RequestBody Video req) {
        return videoService.auditVideo(req);
    }

    @OperatorLog("更新视频的海报")
    @ApiOperation("更新视频的海报")
    @PreAuthorize("hasAuthority('web.video-index.edit.auth')")
    @PostMapping("/updateVideoPoster")
    public BaseResp updateVideoPoster(@RequestBody Video video) {
        return videoService.updateVideoPoster(video);
    }
}
